package com.isoft.controller;

import com.isoft.pojo.dto.ExportRequestDTO;
import com.isoft.result.Result;
import com.isoft.service.ReportService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.servlet.http.HttpServletResponse;
import jakarta.validation.Valid;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.util.Map;

@RestController
@RequestMapping("/admin/lifecycle")
@Tag(name = "生命周期报表接口")
@Slf4j
public class ReportController {
    @Autowired
    private ReportService reportService;
    /**
     * 导出生命周期报表
     * @param response
     */
    @PostMapping("/export")
    @Operation(summary = "导出生命周期报表")
    public void export(@Valid  @RequestBody ExportRequestDTO requestDTO, HttpServletResponse  response){
        reportService.exportBusinessReport(requestDTO,response);
    }
    /**
     * 导入excel文件
     */
    @PostMapping("/import")
    @Operation(summary = "导入生命周期excel表")
    public ResponseEntity<?> importExcel(@RequestParam("file") MultipartFile file){
        log.info("导入生命周期excel表");
        Result<Map<String, Object>> result = reportService.importExcel(file);
        // 正常返回表示部分/全部成功，由 service 抛异常表示失败（由全局异常处理返回422）
        return ResponseEntity.ok(result);
    }
}